﻿using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Library.Classes
{
    internal class Author : INotifyPropertyChanged
    {
        #region Интерфейс INotifyPropertyChanged
        public event PropertyChangedEventHandler? PropertyChanged;

        public void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion

        private int _id = 0;
        private string _lastName = "None";  // Фамилия автора
        private string _firstName = "None"; // Имя автора
        private string _patronymic = "None";// Отчество автора
        private string _description = "";   // Описание автора

        public int Id
        {
            get { return _id; }
            set {
                _id = value;
                NotifyPropertyChanged();
            }
        }
        public string LastName
        {
            get { return _lastName; }
            set {
                _lastName = value;
                NotifyPropertyChanged();
            }
        }
        public string FirstName
        {
            get { return _firstName; }
            set { 
                _firstName = value; 
                NotifyPropertyChanged(); 
            }
        }
        public string Description
        {
            get { return _description; }
            set { 
                _description = value;
                NotifyPropertyChanged();
            }
        }
        public string Patronymic
        {
            get { return _patronymic; }
            set {
                _patronymic = value;
                NotifyPropertyChanged();
            }
        }

        public Author(int id, string lastName, string firstName = "", string patronymic = "", string decsription = "") 
        {
            Id = id;
            LastName = lastName;
            FirstName = firstName;
            Patronymic = patronymic;
            Description = decsription;
        }

        public override string ToString()
        {
            string name = FirstName;
            string patr = Patronymic;
            if (name == String.Empty)
                name = "";
            else
                name = FirstName[0] + ".";

            if (patr == String.Empty)
                patr = "";
            else
                patr = Patronymic[0] + ".";

            return $"{LastName} {name} {patr}";
        }
    }
}